//
//  XHInterActiveViewController.m
//  xinhua_sx
//
//  Created by 党阳阳 on 14-7-29.
//  Copyright (c) 2014年 dangyangyang. All rights reserved.
//
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
#define WRITH  dispatch_queue_create("com.dispatch.writedb", DISPATCH_QUEUE_SERIAL)
#define ff 64
#import "XHInterActiveViewController.h"
#import "AFNetworking.h"
#import "AFHTTPRequestOperation.h"

#import "UIImageView+AFNetworking.h"
#import "UIImageView+WebCache.h"
#import <MediaPlayer/MediaPlayer.h>

#import "NewsDetailViewController.h"
#import "GTMNSString+HTML.h"
#import "shenghuotongWebviewController.h"
#import "ToSayViewController.h"

#import "wangshiViewController.h"
#import "发送图片.h"
#import "custCollectCell.h"

@interface imageCell : UITableViewCell
@property (nonatomic, strong) UIImageView* iv1;
@property (nonatomic, strong) UIImageView* iv2;
@property (nonatomic, strong) UIImageView* iv3;

-(void)setIma:(id)dic tag:(NSInteger)tag;
@end

@implementation imageCell
@synthesize iv1;
@synthesize iv2;
@synthesize iv3;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        iv1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 120)];
        iv1.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:iv1];
        iv2 = [[UIImageView alloc] initWithFrame:CGRectMake(110, 10, 80, 120)];
        iv2.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:iv2];
        iv3 = [[UIImageView alloc] initWithFrame:CGRectMake(210, 10, 80, 120)];
        iv3.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:iv3];
    }
    return self;
}

-(void)setIma:(id)dic tag:(NSInteger)tag
{
    [self setFrame:CGRectMake(0, 0, self.frame.size.width, 140)];

    for (int i = 0; i < 3; i ++)
    {
        if (i == 0 && tag*3 < [dic count])
        {
            NSLog(@"cell = %d  1",tag);
            [iv1 setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",[[dic objectAtIndex:tag*3+0] objectForKey:@"path"]]] placeholderImage:[UIImage imageNamed:@"base_detail_default_pic.png"]];
        }
        else if (i == 1 && tag*3+1 < [dic count])
        {    NSLog(@"cell = %d  2",tag);
             [iv2 setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",[[dic objectAtIndex:tag*3+1] objectForKey:@"path"]]] placeholderImage:[UIImage imageNamed:@"base_detail_default_pic.png"]];
        }
        else if (i  == 2 && tag*3 +2 < [dic count])
        {
            NSLog(@"cell = %d  3",tag);
            [iv3 setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",[[dic objectAtIndex:tag*3+2]objectForKey:@"path"]]] placeholderImage:[UIImage imageNamed:@"base_detail_default_pic.png"]];
        }
    }
    
}

@end


@interface MessageTableViewCell : UITableViewCell
@property (nonatomic ,strong) UILabel *contentLable;
@property (nonatomic ,strong) UILabel *dateLable;
@property (nonatomic ,strong) UILabel *replyLable;
@property (nonatomic, strong) UIView* backView;
@property (nonatomic, strong) UILabel* fengeL1;
@property (nonatomic, strong) UILabel* leixing;
@property (nonatomic, strong) UIView* topView;
-(void)setIDc:(NSDictionary*)dic tag:(id)tag;

@end
@implementation MessageTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _dateLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 160, 21)];
        _contentLable = [[UILabel alloc] initWithFrame:CGRectMake(60, 10, 240, 200)];
        [_dateLable setTintColor:[UIColor grayColor]];
        _backView = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width-20, self.frame.size.height-20)];
        _dateLable.backgroundColor = [UIColor clearColor];
        _contentLable.backgroundColor = [UIColor clearColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.borderColor = [UIColor grayColor].CGColor;
        _backView.backgroundColor = [UIColor orangeColor];
        _leixing = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, 60, 20)];
        _leixing.backgroundColor = [UIColor clearColor];
        _leixing.font = [UIFont systemFontOfSize:14];
        _fengeL1 = [[UILabel alloc] init];
        _fengeL1.backgroundColor = [UIColor blackColor];
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 21)];
        _topView.backgroundColor = [UIColor grayColor];
        _replyLable = [[UILabel alloc] init];
        _replyLable.font = [UIFont systemFontOfSize:12];
        _replyLable.backgroundColor = [UIColor clearColor];
        _replyLable.textColor = [UIColor blueColor];
        _replyLable.textAlignment = NSTextAlignmentRight;
        //[self addSubview:_dateLable];
        //[self addSubview:_contentLable];
        //[self addSubview:_replyLable];
         [self addSubview:_backView];
        [_backView addSubview:_dateLable];
        [_backView addSubview:_contentLable];
        
        [_backView addSubview:_leixing];
        [_backView addSubview:_fengeL1];
        [_backView addSubview:_topView];
        [_backView addSubview:_replyLable];
        
    }
    return self;
}
-(void)setIDc:(NSDictionary*)dic tag:(id)tag
{
    [self.contentLable setNumberOfLines:0];
    self.contentLable.lineBreakMode = NSLineBreakByWordWrapping;//换行方式
    
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    self.contentLable.font = font;
    NSString* leixing = [[dic objectForKey:@"stype"] stringValue];
    if ([leixing isEqualToString:@"0"])
    {
        leixing = @"【举报】";
    }
    else if ([leixing isEqualToString:@"1"])
    {
        leixing = @"【建议】";
    }
    else if ([leixing isEqualToString:@"2"])
    {
        leixing = @"【分享】";
    } else if ([leixing isEqualToString:@"3"])
    {
        leixing = @"【表扬】";
    }
    self.leixing.text = leixing;
    CGSize size = CGSizeMake(200,CGFLOAT_MAX);//标签宽度，固定的
    
    NSString *content =  [dic objectForKey:@"content"];
    
    CGSize labelsize = [content sizeWithFont:font constrainedToSize:size lineBreakMode:self.contentLable.lineBreakMode];
    self.contentLable.frame = CGRectMake(60,10, 200, labelsize.height);
    self.contentLable.text = content;
    self.fengeL1.frame = CGRectMake(0, self.contentLable.frame.size.height+20, 300, 0.5);
    self.dateLable.font = [UIFont systemFontOfSize:12.0];
    self.dateLable.frame = CGRectMake(10, self.contentLable.frame.size.height+22, 160, 21);
    
    self.dateLable.text = [dic objectForKey:@"createDate"];
  
    self.topView.frame = CGRectMake(0, self.dateLable.frame.origin.y-2, 300,22.5);
    self.topView.alpha = 0.5;
    self.replyLable.frame = CGRectMake(170, self.contentLable.frame.size.height+22, 80, 21);
    NSNumber* isReply = [dic objectForKey:@"isReply"];
    if ([isReply isEqualToNumber:@1])
    {
        self.replyLable.text = @"已回复";
    }
    else
    {
        self.replyLable.text = @"未回复";
    }
    [self setFrame:CGRectMake(0, 0, 300, self.contentLable.frame.size.height+41+11)];
    self.backView.frame = CGRectMake(10, 5, self.frame.size.width-20, self.frame.size.height-10);
    self.backView.backgroundColor = [UIColor clearColor];
    self.backView.layer.borderWidth = 1;
    self.backView.layer.borderColor = [UIColor blackColor].CGColor;
    //[self setNeedsDisplay];
    
}
-(void)dealloc
{
    NSLog(@"2");
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
@interface customButton1 : UIButton


@end

@implementation customButton1


-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.titleLabel.font = [UIFont systemFontOfSize:10];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    return  self;
}


-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    
    CGRect tempRect =  CGRectMake(5,11, self.frame.size.width-10, 12);
    return tempRect;
}

@end

@interface XHInterActiveViewController ()

@end

@implementation XHInterActiveViewController
@synthesize allNewDic;
@synthesize buttonArray;
@synthesize tableArray;
@synthesize contentScrollView  = _contentScrollView;
@synthesize titleScrollView = _titleScrollView;
@synthesize titleArray;
@synthesize headerArray;
@synthesize footArrya;
@synthesize BseVIes = _BseVIes;
@synthesize yinitData;
@synthesize damokuai;
@synthesize navBar = _navBar;
@synthesize titleLable = _titleLable;
@synthesize urlstring;
@synthesize iamgeArray;
@synthesize senderButton;
-(void)loadList
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    NSString* stirng = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/categoryListByParent-5-3.html"];
      [manager GET:stirng parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
        if ([responseObject isKindOfClass:[NSArray class]]) {
            self.yinitData = [NSDictionary dictionaryWithObjectsAndKeys:responseObject,@"content", nil] ;
            NSLog(@"%@",(NSDictionary*)responseObject);
            for (id item in self.titleArray)
            {
                
                for (id  item1 in item)
                {
                    // NSLog(@" %@ = %@",item1,item[item1]);
                }
            }
            self.hasLoad = YES;
            [self loadNews33];
        }
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError*error) {
        self.hasLoad = YES;
        NSLog(@"2222%@",error);
    }];

}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.titleArray = [NSMutableArray array];
        self.yinitData = [NSDictionary dictionary];
        self.urlstring = [[XHURLString alloc] init];
        self.iamgeArray = [[NSMutableArray alloc] init];
    }
    return self;
}
-(NSString*)getAREACODe:(NSString*)address
{
    if([@"太原" isEqualToString:address]){
        return @"140100";
    }
    if([@"静乐" isEqualToString:address]){
        return @"035100";
    }
    if([@"大同" isEqualToString:address]){
        return @"037000";
    }
    if([@"阳泉" isEqualToString:address]){
        return @"045000";
    }
    if([@"长治" isEqualToString:address]){
        return @"046001";
    }
    if([@"晋城" isEqualToString:address]){
        return @"048000";
    }
    if([@"朔州" isEqualToString:address]){
        return @"036001";
    }
    if([@"晋中" isEqualToString:address]){
        return @"140700";
    }
    if([@"运城" isEqualToString:address]){
        return @"044000";
    }
    if([@"忻州" isEqualToString:address]){
        return @"034000";
    }
    if([@"临汾" isEqualToString:address]){
        return @"041000";
    }
    if([@"吕梁" isEqualToString:address]){
        return @"033000";
    }
    if([@"小店" isEqualToString:address]){
        return @"140105";
    }
    if([@"古交市" isEqualToString:address]){
        return @"030200";
    }
    if([@"万柏林" isEqualToString:address]){
        return @"030021";
    }
    if([@"晋源" isEqualToString:address]){
        return @"140110";
    }
    if([@"城区" isEqualToString:address]){
        return @"037001";
    }
    if([@"南郊区" isEqualToString:address]){
        return @"037002";
    }
    if([@"浑源" isEqualToString:address]){
        return @"037400";
    }
    if([@"灵丘" isEqualToString:address]){
        return @"034400";
    }
    if([@"阳泉城区" isEqualToString:address]){
        return @"045002";
    }
    if([@"阳泉矿区" isEqualToString:address]){
        return @"045003";
    }
    if([@"阳泉郊区" isEqualToString:address]){
        return @"045001";
    }
    if([@"盂县" isEqualToString:address]){
        return @"045100";
    }
    if([@"长治郊区" isEqualToString:address]){
        return @"046002";
    }
    if([@"襄垣" isEqualToString:address]){
        return @"046200";
    }
    if([@"屯留" isEqualToString:address]){
        return @"046100";
    }
    if([@"长子" isEqualToString:address]){
        return @"046600";
    }
    if([@"晋城城区" isEqualToString:address]){
        return @"048002";
    }
    if([@"沁水" isEqualToString:address]){
        return @"048200";
    }
    if([@"阳城" isEqualToString:address]){
        return @"048100";
    }
    if([@"泽州" isEqualToString:address]){
        return @"048001";
    }
    if([@"朔城区" isEqualToString:address]){
        return @"036002";
    }
    if([@"山阴" isEqualToString:address]){
        return @"036900";
    }
    if([@"怀仁" isEqualToString:address]){
        return @"038300";
    }
    if([@"和顺" isEqualToString:address]){
        return @"032700";
    }
    if([@"寿阳" isEqualToString:address]){
        return @"140725";
    }
    if([@"平遥" isEqualToString:address]){
        return @"031100";
    }
    if([@"灵石" isEqualToString:address]){
        return @"031301";
    }
    if([@"盐湖区" isEqualToString:address]){
        return @"044001";
    }
    if([@"永济" isEqualToString:address]){
        return @"044500";
    }
    if([@"河津" isEqualToString:address]){
        return @"043300";
    }
    if([@"忻府区" isEqualToString:address]){
        return @"034001";
    }
    if([@"定襄" isEqualToString:address]){
        return @"335400";
    }
    if([@"五台" isEqualToString:address]){
        return @"335500";
    }
    if([@"代县" isEqualToString:address]){
        return @"034200";
    }
    if([@"原平" isEqualToString:address]){
        return @"034100";
    }
    if([@"尧都区" isEqualToString:address]){
        return @"041002";
    }
    if([@"洪洞" isEqualToString:address]){
        return @"031600";
    }
    if([@"安泽" isEqualToString:address]){
        return @"042500";
    }
    if([@"离石区" isEqualToString:address]){
        return @"033099";
    }
    if([@"柳林" isEqualToString:address]){
        return @"033300";
    }
    if([@"交口" isEqualToString:address]){
        return @"032499";
    }
    if([@"孝义" isEqualToString:address]){
        return @"032300";
    }
    return @"140000";
    
}
-(void)addRIghtButton
{
    //self presentViewController:<#(UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>
}

-(void)back
{
   // [[AFHTTPRequestOperationManager manager].operationQueue cancelAllOperations];
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSString *)ggetNewsListWithAreaCode:(id)areaCode1 itemId:(id)itemId currentPage:(id)currentPage pageSize:(id)pageSize
{
    if ([damokuai isEqualToString:@"新闻动态"])
    {
        NSString* string = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/articles-list-%@-%@.html?pageNo=%@&pageSize=%@",itemId,areaCode1,currentPage,pageSize];
        return  string;
    }
    else if ([damokuai isEqualToString:@"互动分享"])
    {
        NSString* string = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/suggestionfindByOfficeId-%@.html?pageNo=%@&pageSize=%@",areaCode1,currentPage,pageSize];
        return  string;
    }
    return nil;
}

-(void)rightClick
{
    dishiViewController* viewController = [[dishiViewController alloc] init];
    viewController.block = ^(NSString* str,NSString*fff1)
    {
        if ([fff1 isEqualToString:areaCode])
        {
            NSLog(@"frff= %@",fff1);
            
        }
        
        else
        {
            NSLog(@"333 = %@",fff1);
            areaCode = fff1;
            [self reshrg];
            
        }
        NSLog(@"%@ = %@",fff1,areaCode);
    };
    if ([_titleLable.text isEqualToString:@"地市热点"])
    {
        viewController.s1tring = @"只显示地市";
    }
    
    [self presentViewController:viewController animated:YES completion:nil];
}
-(void)reshrg //刷新
{
    
}
-(void)loadNews33
{
    NSArray* ff1 = [self.yinitData objectForKey:@"content"];
    for (int i = 0; i < [ff1 count]; i ++)
    {
        NSDictionary* dic = [ff1 objectAtIndex:i];
        [self.titleArray addObject:[dic objectForKey:@"name"]];
    }
    
    for (int i = 0; i < [self.titleArray count]; i++)
    {
        NSString* title = [self.titleArray objectAtIndex:i];
        NSInteger titleLeng = [title length];
        customButton1* button = [[customButton1 alloc] initWithFrame:CGRectMake(self.ymNum+10, 0,titleLeng*18, 40)];
        [self.buttonArray addObject:button];
        [button setTag:10000+i];
        button.backgroundColor = [UIColor clearColor];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        if(i == 0)
        {
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.la = [[UIView alloc] initWithFrame:CGRectMake(self.ymNum, 1, titleLeng*18+20, 38)];
            self.la.backgroundColor = [UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f];
            [_titleScrollView addSubview:self.la];
        }
        else
        {
            [button setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        }
        if (i < [self.titleArray count] -1)
        {
            UILabel* l = [[UILabel alloc] initWithFrame:CGRectMake(self.ymNum+20+titleLeng*18, 9, 1, 15)];
            l.backgroundColor = [UIColor grayColor];
            l.alpha = 0.2;
            [_titleScrollView addSubview:l];
        }
        
        [button addTarget:self action:@selector(titleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        self.ymNum = self.ymNum + titleLeng*18 + 20;
        [button setTitle:title forState:UIControlStateNormal];
        
        
        [button.titleLabel setFont:[UIFont fontWithName:@"Arial" size:12.0f]];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        
        [_titleScrollView addSubview:button];
        
    }
    self.titleScrollView.contentSize = CGSizeMake(self.ymNum, 0);
    [self.view addSubview:self.titleScrollView];
    
    UIScrollView* contentScroView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30+ff, 320, self.view.frame.size.height-30-10)];
    contentScroView.delegate = self;
    self.contentScrollView = contentScroView;
    contentScroView.bounces = NO;
    contentScroView.showsHorizontalScrollIndicator = NO;
    contentScroView.showsVerticalScrollIndicator = NO;
    contentScroView.pagingEnabled = YES;
    contentScroView.contentSize = CGSizeMake([self.titleArray count] * 320, 0);
    [self.view addSubview:contentScroView];
    
    self.tableArray = [[NSMutableArray alloc] init];
    self.headerArray = [[NSMutableArray alloc] init];
    self.footArrya = [[NSMutableArray alloc] init];
    for (int i = 0; i < [self.titleArray count]; i++)
    {
        if (i == 1)
        {
            
            //初始化 UICollectionViewController
            UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
            [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

            UICollectionView*  myCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(320*i+10, 0+10, 300, self.view.frame.size.height-80-30-20-10) collectionViewLayout:flowLayout];
            [myCollectionView registerClass:[custCollectCell class] forCellWithReuseIdentifier:@"cell"];
            myCollectionView.backgroundColor=[UIColor whiteColor];
            myCollectionView.delegate=self;
            myCollectionView.dataSource=self;
            [_contentScrollView addSubview:myCollectionView];
            [self.tableArray addObject:myCollectionView];
            break;
            
        }
        UITableView* tableView = [[UITableView alloc] initWithFrame:CGRectMake(320*i+10, 0+10, 300, self.view.frame.size.height-80-30-20-10)];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tag = 20000 + i;
       // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [tableView setSeparatorInset:UIEdgeInsetsZero];
        }
        //[tableView setSeparatorColor:[UIColor clearColor]];
        //tableView.bounces = NO;;
        tableView.backgroundColor = [UIColor clearColor];
        
        MJRefreshHeaderView* headerView = [MJRefreshHeaderView header];
        MJRefreshFooterView* footerView = [MJRefreshFooterView footer];
        headerView.delegate = self;
        footerView.delegate = self;
        headerView.tag = 30000+i;
        footerView.tag = 40000+i;
        
        headerView.scrollView = tableView;
        footerView.scrollView = tableView;
        NSDate * now = [NSDate date];
        NSDate * anHourAgo = [now dateByAddingTimeInterval:-60*5];
        [headerView setLastUpdateTime:anHourAgo];
        [self.headerArray addObject:headerView];
        [self.footArrya addObject:footerView];
        [self.tableArray addObject:tableView];
        [self.contentScrollView addSubview:tableView];
       
    }
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height-30, 320, 30)];
    [button setTitle:@"我要说" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(wyaos) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[XHInterActiveViewController colorWithHexString:@"#A6C4E8"]];
    [self.view addSubview:button];
    self.senderButton = button;
    NSLog(@"init = %d",[self.tableArray count]);
    //[[self.headerArray objectAtIndex:0] beginRefreshing];
    [self loadNews:0 page:@"0" pageSize:@"10"];
}
#pragma mark - collectionView delegate
//设置分区
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

//每个分区上的元素个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.iamgeArray count];
}

//设置元素内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"cell";
    custCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    //[cell sizeToFit];
    if (!cell) {
     
    }
    cell.imageView.tag = indexPath.row;
    [cell setDic:[self.iamgeArray objectAtIndex:indexPath.row]];
    
  
   // VideoModel *model = [self.videoModels objectAtIndex:indexPath.row];
   // NSURL *url = [NSURL URLWithString:model.videoImgURL];
    
    // [cell setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",[[self.iamgeArray objectAtIndex:indexPath.row] objectForKey:@"path"]]] placeholderImage:[UIImage imageNamed:@"base_detail_default_pic.png"]];
    return cell;
}

//设置元素的的大小框
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UIEdgeInsets top = {5,10,15,5};
    return top;
}

//设置顶部的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    CGSize size={0,0};
    return size;
}
//设置元素大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    //NSLog(@"%f",(kDeviceHeight-88-49)/4.0);
    return CGSizeMake(80,120);
}

//点击元素触发事件

#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"ff=%d",indexPath.row);
    //UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    //cell.backgroundColor = [UIColor whiteColor];
    int count = [self.iamgeArray count];
   
    // 1.封装图片数据
    NSMutableArray *photos = [NSMutableArray arrayWithCapacity:1];
   // for (int i = 0; i<count; i++) {
        // 替换为中等尺寸图片
        NSString *url =  [NSString stringWithFormat:@"http://183.203.18.45:7001%@",[[self.iamgeArray objectAtIndex:indexPath.row] objectForKey:@"path"]]; //[[[self.iamgeArray objectAtIndex:i] objectForKey:@"path"] stringByReplacingOccurrencesOfString:@"thumbnail" withString:@"bmiddle"];
        MJPhoto *photo = [[MJPhoto alloc] init];
        photo.url = [NSURL URLWithString:url]; // 图片路径
       // 来源于哪个UIImageView
       custCollectCell*  cell = (custCollectCell*)[collectionView cellForItemAtIndexPath:indexPath]  ;
        photo.srcImageView = cell.imageView;
        [photos addObject:photo];
       // cell = nil;
    //}
    
    // 2.显示相册
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
   // browser.currentPhotoIndex = 0; // 弹出相册时显示的第一张图片是？
    browser.photos = photos; // 设置所有的图片
    [browser show];
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _contentScrollView.frame = CGRectMake(0, 15+ff, 320, self.view.frame.size.height-30-10);
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        //拍照
        
        [self pickPhotoWithSource:UIImagePickerControllerSourceTypeCamera];
        return;
        
    }
    if (buttonIndex == 1) {
        // 选取图片
        [self pickPhotoWithSource:UIImagePickerControllerSourceTypePhotoLibrary];
        
        return;
        
    }
    return;
}

- (void)pickPhotoWithSource:(UIImagePickerControllerSourceType )source
{
    //创建图片选择器
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    
    //指定源类型前，检查图片源是否可用
    if ([UIImagePickerController isSourceTypeAvailable:source])
    {
        //指定源的类型
        imagePicker.sourceType = source;
        
        //在选定图片之前，用户可以简单编辑要选的图片。包括上下移动改变图片的选取范围，用手捏合动作改变图片的大小等。
        imagePicker.allowsEditing = YES;
        
        //实现委托，委托必须实现UIImagePickerControllerDelegate协议，来对用户在图片选取器中的动作
        imagePicker.delegate = self;
        
        //设置完iamgePicker后，就可以启动了。用以下方法将图像选取器的视图“推”出来
        [self presentModalViewController:imagePicker animated:YES];
        
        
    }
    else
    {
        UIAlertView *alert =[[UIAlertView alloc] initWithTitle:nil message:@"相机不能用" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [alert show];
        
    }
}

#pragma  mark UIImagePickerControllerDelegate协议的方法

//用户点击图像选取器中的“cancel”按钮时被调用，这说明用户想要中止选取图像的操作
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
   // [picker dismissModalViewControllerAnimated:YES];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//用户点击选取器中的“choose”按钮时被调用，告知委托对象，选取操作已经完成，同时将返回选取图片的实例
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    
    //上传图片
    
    //_image= image;
   // [_photo setImage:_image forState:UIControlStateNormal];
    NSLog(@"image %@",image);
    //[picker dismissModalViewControllerAnimated:YES];
    [picker dismissViewControllerAnimated:YES completion:nil];
    sendimageVieControll* vie1 = [[sendimageVieControll alloc] init];
    vie1.iamge = image;
    [self.navigationController pushViewController:vie1 animated:YES];

    
} 

-(void)wyaos
{
    if (selectButton == 1)
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:@"选取图片或拍照"
                                      delegate:self
                                      cancelButtonTitle:@"取消"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"拍照", @"从相册选取",nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [actionSheet showInView:self.view];
    }
    else
    {
        ToSayViewController *sayViewController = [[ToSayViewController alloc] init];
        [self.navigationController pushViewController:sayViewController animated:YES];
    }
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
  

    damokuai = @"互动分享";
    
    if ([self respondsToSelector:@selector(setTintColor:)])
    {
        [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    }
    
    self.view.backgroundColor = [UIColor whiteColor];
    CGFloat aY = kIOS_VERSION<7.0?0:20;
    
    _navBar = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0+aY)];
    _navBar.backgroundColor = [UIColor colorWithRed:2.0/255 green:102.0/255 blue:172.0/255 alpha:1.0];
    _navBar.userInteractionEnabled = YES;
    
    _titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, aY, self.view.frame.size.width, 44)];
    _titleLable.backgroundColor = [UIColor clearColor];
    _titleLable.text = @"互动分享";
    _titleLable.textColor = [UIColor whiteColor];
    _titleLable.font = [UIFont systemFontOfSize:20];
    _titleLable.textAlignment = NSTextAlignmentCenter;
    
    [_navBar addSubview:_titleLable];
    [self.view addSubview:_navBar];
    UIButton* _leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, aY, 40,40.0)];
    [_leftButton setImage:[UIImage imageNamed:@"icon_back@2x.png"] forState:UIControlStateNormal];
    _leftButton.imageEdgeInsets = UIEdgeInsetsMake(10, 13, 5, 5);
    [_leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_leftButton];

    areaCode = COUTURYCODE;// [self getAREACODe:COUTURYNAME];//复制时替换成 县区名字;
    UIButton* _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-40, 5+aY, 40, 40)];
        [_rightButton setImage:[UIImage imageNamed:@"tab_spinner_normal.png"] forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
        //[self.view addSubview:_rightButton];
        

    
    // Do any additional setup after loading the view, typically from a nib.
    
    self.allNewDic = [[NSMutableDictionary alloc] init];
    //   self.view.userInteractionEnabled=YES; //UIView是否接受并响应用户的交互
    // 58 133 201
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gmModelNoticicationCenterMethod:) name:@"modelNCOne3" object:Nil];
    UIScrollView* titleScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0+ff, 320, 40)];
    //self.titleScrollView.backgroundColor = [UIColor blackColor];
    self.titleScrollView = titleScrollView;
    titleScrollView.showsHorizontalScrollIndicator = NO;
    [titleScrollView setBackgroundColor:[XHInterActiveViewController colorWithHexString:@"DFDFDF"]];
    titleScrollView.bounces = NO;
    //self.titleArray = [[NSMutableArray alloc] init];
    self.buttonArray = [[NSMutableArray alloc] init];
    _BseVIes = [[MJRefreshBaseView alloc] init];
    
    // self.titleArray = [NSMutableArray arrayWithObjects:@"公司新闻",@"视频新闻",@"太钢日报",@"媒体看太钢",nil];
    selectButton = 0;
    isRefresh  = YES;
    [self loadList];
    [self loadImage];
  
    
}






-(void)gmModelNoticicationCenterMethod:(id)sender{
    
    NSInteger theCategroy = [[[sender userInfo] objectForKey:@"theCategroy"] intValue];
    
    [self gmTransferDataToTableView:theCategroy];
    
    
    
    
    //使用其它线程对数据存档
    if(self.allNewDic){
        dispatch_queue_t curQueueFour = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_async(curQueueFour, ^{
            
        });
    }
    
    
}

-(void)gmTransferDataToTableView:(NSInteger)theCategory{
    
    dispatch_queue_t curQueueTwo = dispatch_get_main_queue();
    
    dispatch_async(curQueueTwo, ^{
        NSLog(@"222=  %d",theCategory);
        [[self.tableArray objectAtIndex:theCategory] reloadData];
        NSLog(@"%@reload 完成",[self.titleArray objectAtIndex:theCategory]);
        [[self.headerArray objectAtIndex:theCategory] endRefreshing];
        [[self.footArrya objectAtIndex:theCategory] endRefreshing];
    });
}

-(void)gmRequestNetData:(NSInteger)theModelid{
    
    dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(curQueue, ^{
        [self loadNews:theModelid page:@"0" pageSize:@"10"];
    });
    
}
/*
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat hff = 44.0;
    for (int i= 0; i < [self.titleArray count]; i ++)
    {
        if (tableView.tag == 20000+ i)
        {
            
            NSDictionary* ara = [self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]];
            NSLog(@"ara = %d",[ara count]);
            
            NSString* string = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]]  objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"content"];
            CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
            //CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
            NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:11]};
            CGSize size = [string boundingRectWithSize:CGSizeMake(240, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
            hff = size.height+20;
            
            
            
        }
    }
    NSLog(@"hff = %lf",hff);
    return hff;
}
*/
-(void)loadImage
{///xinhua/m/getPhotosHandByCode-140725.html
    NSString* str = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/getPhotosHandByCode-%@.html",COUTURYCODE];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
        id jsonObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                        options:NSJSONReadingAllowFragments
                                                          error:nil];
        NSLog(@"json =- %@",jsonObject);
        if ( [jsonObject count] > 0)
        {
            self.iamgeArray = jsonObject;
           
            
           // NSLog(@"imageArray = %@ = %d",self.iamgeArray,[self.iamgeArray count]);
            [[self.tableArray objectAtIndex:1] reloadData];
            //[[self.headerArray objectAtIndex:1]  endRefreshing];
           // [[self.footArrya objectAtIndex:1] endRefreshing];
            //[[self.tableArray objectAtIndex:1] reloadData];
            dispatch_queue_t curQueueTwo = dispatch_get_main_queue();
            
            dispatch_async(curQueueTwo, ^{
               // [[self.tableArray objectAtIndex:1] reloadData];
               
               // [[self.headerArray objectAtIndex:1] endRefreshing];
               // [[self.footArrya objectAtIndex:1] endRefreshing];
            });
          
            
        }
        
    }
    failure:^(AFHTTPRequestOperation *operation, NSError*error) {
             NSLog(@"Error: %@", error);
           // [[self.headerArray objectAtIndex:1]  endRefreshing];
            //[[self.footArrya objectAtIndex:1] endRefreshing];
         }];
    // _BseVIes = nil;
    
}
-(void)loadNews:(NSInteger)i page:(NSString*)j pageSize:(NSString*)k
{
    NSNumber* newId;
    NSArray* ff1 = [self.yinitData objectForKey:@"content"];
    //NSString* str = [self.urlstring getNewsListWithAreaCode:areaCode itemId: [[ff1 objectAtIndex:i] objectForKey:@"id"] currentPage:j pageSize:k]
     NSString* str;
    if (i == 0)
    {
          str = [self ggetNewsListWithAreaCode:areaCode itemId:[[ff1 objectAtIndex:i] objectForKey:@"id"] currentPage:j pageSize:k];
    }
    else
    {
        [self loadImage];
        return;
    }
    
    NSLog(@"rtl = %@",str);
    BOOL ishgg = isRefresh;
    //NSLog([@"%@ 开始加载数据   page =%@ ",[self.titleArray objectAtIndex:i],j);
    NSDictionary *tempCategory = [[NSDictionary alloc ] initWithObjectsAndKeys:[NSString stringWithFormat:@"%ld",(long)i],@"theCategroy", nil];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
        ////NSLog([@"JSON: %@", responseObject);
        id jsonObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                        options:NSJSONReadingAllowFragments
                                                          error:nil];
        NSLog(@"json =- %@",jsonObject);
        // //NSLog([@"COUNT = %lu",(unsigned long)[jsonObject count]);
        NSArray* array = [jsonObject objectForKey:@"content"];
        NSLog(@"array = %d",[array count]);
        dispatch_async(WRITH, ^{
            if (ishgg)
            {
                //NSLog([@" %@写入 page = %@ 刷新",[self.titleArray objectAtIndex:i],j);
                ////NSLog([@"%@ is ",[self.titleArray objectAtIndex:i]);
                
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:array,@"content",[jsonObject objectForKey:@"last"],@"last",[jsonObject objectForKey:@"currentPage"],@"currentPage", nil];
                [self.allNewDic removeObjectForKey:[self.titleArray objectAtIndex:i]];
                [self.allNewDic setObject:jsonObject forKey:[self.titleArray objectAtIndex:i]];
                
            }
            else{
                //NSLog([@" %@写入 更多",[self.titleArray objectAtIndex:i]);
                
                
                NSMutableArray* oldContentArray = [[NSMutableArray alloc] init];
                [oldContentArray addObjectsFromArray:[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"]];
                [oldContentArray addObjectsFromArray:array];
                
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:oldContentArray,@"content",[jsonObject objectForKey:@"last"],@"last",[jsonObject objectForKey:@"currentPage"],@"currentPage", nil];
                
                [self.allNewDic removeObjectForKey:[self.titleArray objectAtIndex:i]];
                [self.allNewDic setObject:dic forKey:[self.titleArray objectAtIndex:i]];
                
                
            }
            //[self performSelector:@selector(doneWithView:) withObject:_BseVIes afterDelay:0.0];
            //NSLog([@" %@写入 page = %@ 完成",[self.titleArray objectAtIndex:i],j);
            NSNotification *endData = [NSNotification notificationWithName:@"modelNCOne3" object:nil userInfo:tempCategory];
            [[NSNotificationCenter defaultCenter] postNotification:endData];
            
        });
        //[self performSelector:@selector(fff:) withObject:i afterDelay:2.0];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError*error) {
        NSLog(@"Error: %@", error);
        
        [[self.headerArray objectAtIndex:i]  endRefreshing];
        [[self.footArrya objectAtIndex:i] endRefreshing];
    }];
    
    
    
    
    
    
    
}

-(void)fff:(NSInteger)i
{
    
    //NSLog([@"reloadData");
    [[self.tableArray objectAtIndex:i] reloadData];
    [[self.tableArray objectAtIndex:i] reloadSectionIndexTitles];
    [[self.headerArray objectAtIndex:i]  endRefreshing];
    [[self.footArrya objectAtIndex:i] endRefreshing];
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger j = 0;
    for (int i= 0; i < [self.titleArray count]; i ++)
    {
        if (tableView.tag == 20000+ i)
        {
            
            if(i == 1)
            {
                if ([self.iamgeArray count] %3 == 0)
                    j = [self.iamgeArray count] / 3;
                else
                    j= [self.iamgeArray count] / 3 +1;
                NSLog(@"j = %d",j);
            }
            else
            {
                NSLog(@"fff");
                NSArray* ara = [self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]];
                NSLog(@"ara = %d",[ara count]);
                j =[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] count];
                
                NSLog(@"%@ 总共 %d行",[self.titleArray objectAtIndex:i],j);

            }
        }
    }
    self.endtabCell = j;
    return j;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    for(int i = 0;i < [self.titleArray count];i ++)
    {
       

        if( tableView.tag == 20000 + i && i == 0)
        {
            NSLog(@" cell 0;");
            MessageTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"222"];
            if (cell == nil)
            {
                cell = [[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"222"];
            }
            
            cell.opaque = NO;
           
            NSDictionary* dic = [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row];
            [cell setIDc:dic tag:nil];
          
            return cell;

        }
        else if (tableView.tag == 20000+ i && i == 1)
        {
           
        }
    }
    
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(NSString *)filterHTML:(NSString *)html
{
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text = nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<" intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">" intoString:&text];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
    }
    //    NSString * regEx = @"<([^>]*)>";
    //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
    return html;
}
- (UIImage *)capture
{
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return img;
}
+ (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    for(int i = 0;i < [self.titleArray count];i ++){
        if(tableView.tag == 20000+i){
            
            if (i == 0)
            {
                NSNumber* ef = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"id"];
                wangshiViewController* viewC = [[wangshiViewController alloc] init];
                viewC.string = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/f/suggestion-%@.html",[ef stringValue]];
                NSLog(@"url = %@",viewC.string);
                [self.navigationController pushViewController:viewC animated:YES];
            }
            else if (i == 1)
            {
                
            }
            }
        }
    
}
-(void)moviePlayerPreloadDidFinish:(id)sender
{
    
}
-(void)titleButtonAction:(UIButton *)button
{
    
    if (button.tag- 10000 == selectButton)
    {
        return;
    }
     _contentScrollView.frame = CGRectMake(0, 30+ff, 320, self.view.frame.size.height-30-10);
    //[[self.headerArray objectAtIndex:selectButton] endRefreshing];
    //[[self.footArrya objectAtIndex:selectButton] endRefreshing];
    [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //[[self.buttonArray objectAtIndex:selectButton] setBackgroundColor:[UIColor whiteColor]];
    [button setBackgroundColor:[UIColor clearColor]];
    selectButton = button.tag - 10000;
    
    [self.contentScrollView setContentOffset:CGPointMake(320*selectButton, 0) ];
    /*id lastdata = [[self.headerArray objectAtIndex:selectButton] lastUpdateTime] ;
    
    NSTimeInterval item = [lastdata timeIntervalSinceNow];
    
    if(abs(item) > 300          )
    {
        //[[self.headerArray objectAtIndex:selectButton] beginRefreshing];
        //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        //dispatch_async(curQueue, ^{
        //[self gmRequestNewsData:button.tag-10000];
       // [[self.headerArray objectAtIndex:selectButton] beginRefreshing];
        //});
    }*/
    if (selectButton == 0)
    {
        [UIView animateWithDuration:0.2 animations:^{
            //  [self.titleScrollView setContentOffset:CGPointMake(0, 0)];
            
        }];
        
    }
    else if (selectButton == [self.tableArray count] -1)
    {
        NSLog(@"frame = %f %f  %f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x);
        [UIView animateWithDuration:0.2 animations:^{
            //  [self.titleScrollView setContentOffset:CGPointMake(button.frame.size.width-320+button.frame.origin.x, 0)];
            
        }];
    }
    else
    {
        NSLog(@"frame = %f %f  %f,%f  %f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x,self.titleScrollView.contentOffset.x);
    }
    if(button.center.x > 100 && button.center.x < self.ymNum-90){
        
    }
    [UIView animateWithDuration:0.2 animations:^{
        self.la.frame = CGRectMake(button.frame.origin.x-10, 1, button.frame.size.width+20, 38);
        
        
    }];
    if (button.tag == 10000)
    {
        [senderButton setTitle:@"我要说" forState:UIControlStateNormal];
    }
    else
    {
        [senderButton setTitle:@"我要拍" forState:UIControlStateNormal];
    }
    
    
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    //  self.stratDragPoint = scrollView.contentOffset;//开始点
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    self.EndDragPoint = scrollView.contentOffset;//结束点
    
    
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    CGPoint tempPoint = scrollView.contentOffset;
    NSInteger tempSelect = tempPoint.x/320;
    
    ////NSLog([@"%ld = %ld",(long)selectButton, (long)tempSelect);
    if (self.EndDragPoint.y == 0 && (tempSelect != selectButton))
    {
        
        [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        selectButton = tempSelect;
        [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        /*
        id lastdata = [[self.headerArray objectAtIndex:selectButton] lastUpdateTime] ;
        // //NSLog([@"lastdata=%@",[lastdata class]);
        NSTimeInterval item = [lastdata timeIntervalSinceNow];
        if(abs(item) > 300          )
        {
            //[[self.headerArray objectAtIndex:selectButton] beginRefreshing];
            // dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
            // dispatch_async(curQueue, ^{
            //跟新数据，要去数据请求
            // [self gmRequestNewsData:selectButton+10000];
            //[[self.headerArray objectAtIndex:selectButton] beginRefreshing];
            // });
        }*/
        UIButton* button = [self.buttonArray objectAtIndex:selectButton];
        if (selectButton == 0)
        {
            [UIView animateWithDuration:0.2 animations:^{
                // [self.titleScrollView setContentOffset:CGPointMake(0, 0)];
                
            }];
            
        }
        else if (selectButton == [self.tableArray count] -1)
        {
            NSLog(@"frame = %f %f  %f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x);
            [UIView animateWithDuration:0.2 animations:^{
                // [self.titleScrollView setContentOffset:CGPointMake(button.frame.size.width-320+button.frame.origin.x, 0)];
                
            }];
        }
        else
        {
            NSLog(@"frame = %f %f  %f,%f  %f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x,self.titleScrollView.contentOffset.x);
        }
        if(button.center.x > 100 && button.center.x < self.ymNum-90){
            
        }
        [UIView animateWithDuration:0.2 animations:^{
            self.la.frame = CGRectMake(button.frame.origin.x-10, 1, button.frame.size.width+20, 38);
            
            
        }];
        if (button.tag == 10000)
        {
            [senderButton setTitle:@"我要说" forState:UIControlStateNormal];
        }
        else
        {
            [senderButton setTitle:@"我要拍" forState:UIControlStateNormal];
        }
        
    }
    
    
    
}



#pragma mark - 刷新控件的代理方法
#pragma mark 开始进入刷新状态
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    // //NSLog(@%@----开始进入刷新状态, refreshView.class);
    // 2.2秒后刷新表格UI
    //[self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:2.0];
    //NSLog([@"retag =%d",refreshView.tag);
    if ([refreshView.class isSubclassOfClass:[MJRefreshHeaderView class]])
    {
        for (int i=0; i < [self.headerArray count]; i++)
        {
            if (refreshView.tag == 30000+i)
            {
                isRefresh = YES;
                _BseVIes = nil;
                _BseVIes = refreshView;
                if (i != 0)
                {
                    [refreshView endRefreshing];
                   return;
                }
                [self gmRequestNetData:i];
            }
        }
    }
    else if ([refreshView.class isSubclassOfClass:[MJRefreshFooterView class]])
    {
        for (int i = 0; i < [self.footArrya count]; i ++)
        {
            if (refreshView.tag == 40000+ i)
            {
                
                isRefresh = NO;
                _BseVIes = nil;
                _BseVIes = refreshView;
                
                NSString* countPage =  [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"last"];
                NSUInteger couf =  [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] count];
                NSLog(@" a = %d, b= %u",couf/10, [countPage intValue]);
                if (couf%10 != 0)
                {
                    [refreshView endRefreshing];
                    return;
                }
                if ( couf/10 >= [countPage intValue] )
                {
                    [refreshView endRefreshing];
                    return;
                }
                
                NSString* st = [NSString stringWithFormat:@"%d",couf/10 +1] ;
                
                dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
                dispatch_async(curQueue, ^{
                    
                    [self loadNews:i page:st pageSize:@"10"];
                });
                
            }
        }
    }
    /*
     if ([self.headerArray objectAtIndex:selectButton] == refreshView)
     {
     isRefresh = YES;
     _BseVIes = nil;
     _BseVIes = refreshView;
     //NSNumber* i = [[_array objectAtIndex:selectButton] objectForKey:@"id"];
     int i = self.contentScrollView.contentOffset.x/320;
     
     //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
     //dispatch_async(curQueue, ^{
     [self gmRequestNetData:i];
     // [self loadNews:i page:@"1" pageSize:@"10"];
     // });
     }
     else
     {
     NSNumber* lastPage =  [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"lastPage"];
     if ([lastPage isEqualToNumber:@1])
     {
     [refreshView endRefreshing];
     return;
     }
     ////NSLog([@"sf==%d ",[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] /10);
     if ([[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] /10 ==0 || [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] %10 != 0)
     {
     
     
     [refreshView endRefreshing];
     return;
     }
     isRefresh = NO;
     _BseVIes = nil;
     _BseVIes = refreshView;
     NSNumber* next = [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"next"];
     NSNumber* last = [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"last"];
     
     
     if (next <= last )
     {
     int i = self.contentScrollView.contentOffset.x/320;
     // NSNumber* i = [[_array objectAtIndex:selectButton] objectForKey:@"id"];
     NSString* st = [next stringValue];
     //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
     // dispatch_async(curQueue, ^{
     [self gmRequestNetData:i];
     //[self loadNews:i page:st pageSize:@"10"];
     //});
     
     }
     
     
     }*/
    
}



#pragma mark 刷新完毕
- (void)refreshViewEndRefreshing:(MJRefreshBaseView *)refreshView
{
    ////NSLog(@%@----刷新完毕, refreshView.class);
}

#pragma mark 监听刷新状态的改变
- (void)refreshView:(MJRefreshBaseView *)refreshView stateChange:(MJRefreshState)state
{
    switch (state) {
        case MJRefreshStateNormal:
            // //NSLog(@%@----切换到：普通状态, refreshView.class);
            break;
            
        case MJRefreshStatePulling:
            // //NSLog(@%@----切换到：松开即可刷新的状态, refreshView.class);
            break;
            
        case MJRefreshStateRefreshing:
            // //NSLog(@%@----切换到：正在刷新状态, refreshView.class);
            break;
        default:
            break;
    }
}

#pragma mark 刷新表格并且结束正在刷新状态
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    // 刷新表格
    //[myTableView reloadData];
    
    // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
    NSLog(@"刷新表格");
    _BseVIes = nil;
    [[self.tableArray objectAtIndex:0] reloadData];
    [refreshView endRefreshing];
}

-(void)dealloc
{
    NSLog(@"dealloc1");
    
    for (int i = 0; i < [self.headerArray count]; i++)
    {
        [[self.headerArray objectAtIndex:i] free];
    }
    for (int i = 0; i < [self.footArrya count]; i++)
    {
        [[self.footArrya objectAtIndex:i] free];
    }
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"modelNCOne3" object:Nil];
    self.tableArray = nil;
    self.contentScrollView = nil;
    self.titleArray = nil;
    self.allNewDic = nil;
    
}
- (void)clearTmpPics
{
    [[SDImageCache sharedImageCache] clearDisk];
    
    //    [[SDImageCache sharedImageCache] clearMemory];//可有可无
    
    //DLog(@"clear disk");
    
   // float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize];
    
   // NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024];
   // NSLog(@"清除= %@",clearCacheName);
    //[configDataArray replaceObjectAtIndex:2 withObject:clearCacheName];
    
   // [configTableView reloadData];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    //清除缓存：
    NSLog(@"清除");
    [self clearTmpPics];
   // [[SDImageCache sharedImageCache] clearDisk];
    
   // [[SDImageCache sharedImageCache] clearMemory];
    // Dis
    
#pragma mark - 刷新控件的代理方法
#pragma mark 开始进入刷新状态
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end


@implementation customTablViewCell2;
@synthesize titleLable;
@synthesize chakanLable;
@synthesize imageView1;
@synthesize deLable;
@synthesize textView;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor blackColor];
        UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.frame.size.width-10, self.frame.size.height-10)];
        backgroundView.layer.borderWidth = 0.15;
        backgroundView.layer.borderColor = [UIColor grayColor].CGColor;
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 300, 18)];
        self.titleLable.font = [UIFont systemFontOfSize:15];
        self.titleLable.textColor = [UIColor blackColor];
        self.titleLable.textAlignment = NSTextAlignmentLeft;
        self.titleLable.backgroundColor = [UIColor clearColor];
        //[self addSubview:self.titleLable];
        
        self.deLable = [[UILabel alloc] initWithFrame:CGRectMake(70, 8, 240, self.frame.size.height-10)];
        self.deLable.font = [UIFont systemFontOfSize:11];
        self.deLable.textColor = [UIColor grayColor];
        self.deLable.textAlignment = NSTextAlignmentLeft;
        self.deLable.numberOfLines = 3;
        self.deLable.backgroundColor = [UIColor clearColor];
        //[self addSubview:self.deLable];
        
        self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(8, 20, 55, 50)];
        imageView1.contentMode = UIViewContentModeScaleToFill;
        // imageView1.backgroundColor = [UIColor grayColor];
        imageView1.image = [UIImage imageNamed:@"base_list_default_icon.png"];
       // [self addSubview:imageView1];
    
        
        
        self.chakanLable = [[UILabel alloc] initWithFrame:CGRectMake(260,60 , 40, 10)];
        self.chakanLable.font = [UIFont systemFontOfSize:8];
        self.chakanLable.textColor = [UIColor grayColor];
        self.chakanLable.textAlignment = NSTextAlignmentLeft;
        self.chakanLable.backgroundColor = [UIColor clearColor];
        self.chakanLable.text = @"0";
        //[self addSubview:chakanLable];
        UIImageView* imagevs = [[UIImageView alloc] initWithFrame:CGRectMake(245, 60, 10, 10)];
        imagevs.contentMode = UIViewContentModeScaleToFill;
        imagevs.backgroundColor = [UIColor clearColor];
        imagevs.image = [UIImage imageNamed:@"news_listview_item_attention.png"];
        //[self addSubview:imagevs];
        //[self addSubview:backgroundView];
        self.textView = [[UITextView alloc] initWithFrame:CGRectMake(80, 8, 210, self.frame.size.height-8)];
        textView.backgroundColor = [UIColor whiteColor];
        textView.font = [UIFont systemFontOfSize:11];
        textView.editable = NO;
        textView.scrollEnabled = NO;
        [backgroundView addSubview:self.textView];
       
        
    }
    return self;
}


-(void)setDic:(NSDictionary*)dic tag:(NSInteger)tag
{
    NSString* title = [dic objectForKey:@"title"];
    //title = [self filterHTML:title];
    title = [title gtm_stringByUnescapingFromHTML];
    self.titleLable.text = title;
    NSString* det = [dic  objectForKey:@"content"];
    
    det = [self filterHTML:det];
    det = [det gtm_stringByUnescapingFromHTML];
    
    self.textView.text =  det;
    
    
    
    NSString* string  = [dic  objectForKey:@"image"];
    //NSLog([@"photo = %@",string);
    if ([string length] > 0 && ![string isEqualToString:@"null"])
    {
        NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",string]];
        [self.imageView1 setImageWithURL:url placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",title]]];
    }
    /* NSString* neid = [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectAtIndex:indexPath.row]  objectForKey:@"id"];
     NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.tisco.com.cn%@",string]];
     [cell.imageView1 setImageWithURL:url placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",neid]]];
     NSNumber* hits = [NSNumber numberWithInt:0];
     NSString* f = [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectAtIndex:indexPath.row]  objectForKey:@"agencyId"];
     ////NSLog([@"hits leng= %d",[hits intValue]);
     //NSString* f =[NSString stringWithFormat:@"%d",[hits intValue]];
     cell.chakanLable.text = f;*/
    id hits = [dic objectForKey:@"hits"];
    
    
    NSString* string22 = [NSString stringWithFormat:@"%@",hits];
    //NSLog([@"stt = %@,value = %d",string22,[string22 length]);
    if (![string22 isEqualToString:@"(null)"])
    {
        self.chakanLable.text = string22;
    }
}
-(NSString *)filterHTML:(NSString *)html
{
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text = nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<" intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">" intoString:&text];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
    }
    //    NSString * regEx = @"<([^>]*)>";
    //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
    return html;
}
-(void)dealloc
{
    NSLog(@"dealloc");
    
}


@end
